<!DOCTYPE html><html><head><title>README</title><link href="http://www.jboss.org/jdf/stylesheets/documentation.css" rel="stylesheet"></link><link href="http://www.jboss.org/jdf/stylesheets/pygments.css" rel="stylesheet"></link></head><body>
<h1><a id="kitchensinkml-localized-application-using-an-assortment-of-technologies-including-arquillian" class="anchor" href="#kitchensinkml-localized-application-using-an-assortment-of-technologies-including-arquillian"><span class="anchor-icon"></span></a>kitchensink-ml: Localized application using an assortment of technologies including Arquillian</h1>

<p>Author: Sande Gilda<br/>
Level: Intermediate<br/>
Technologies: CDI, JSF, JPA, EJB, JPA, JAX-RS, BV<br/>
Summary: A localized version of kitchensink<br/>
Target Product: EAP<br/>
Product Versions: EAP 6.1, EAP 6.2<br/>
Source: <a href="https://github.com/jboss-developer/jboss-eap-quickstarts/">https://github.com/jboss-developer/jboss-eap-quickstarts/</a>  </p>

<h2><a id="what-is-it" class="anchor" href="#what-is-it"><span class="anchor-icon"></span></a>What is it?</h2>

<p>This is your project! It is a sample, deployable Maven 3 project to help you get your foot in the door developing with Java EE 6 on Red Hat JBoss Enterprise Application Platform. </p>

<p>This project is setup to allow you to create a <em>localized</em> Java EE 6 compliant application using JSF 2.0, CDI 1.0, EJB 3.1, JPA 2.0 and Bean Validation 1.0. A localized application is one that supports multiple languages. That is what the <em>-ml</em> suffix denotes in the quickstart name <code>kitchensink-ml</code>. This quickstart also includes a persistence unit and some sample persistence and transaction code to introduce you to database access in enterprise Java. </p>

<p>This quickstart uses the <code>kitchensink</code> quickstart as its starting point. It has been enhanced to provide localization of labels and messages. A user sets the preferred language choice in the browser and, if the application supports that language, the application web page is rendered in that language. For demonstration purposes, this quickstart has been tranlated into French(fr) and Spanish (es) using <a href="http://translate.google.com">http://translate.google.com</a>, so the translations may not be ideal.</p>

<h3><a id="localization-code-changes" class="anchor" href="#localization-code-changes"><span class="anchor-icon"></span></a>Localization Code Changes</h3>

<p>The following changes were made to the quickstart to enable it to use the browser preferred locale setting when displaying the web page:</p>

<ul>
<li><p>Properties files were created for the supported languages. </p>

<ul>
<li>This quickstart is localized for Spanish  and  French. You can add additional language support by creating properties files with the appropriate suffix and populating the properties with translated values.</li>
<li>The JSF resource Bundle is located at `src/main/resources/org/jboss/as/quickstarts/kitchensink/bundle/Resources_(es|fr).properties</li>
<li>Messages generated by Java code (e.g. log messages and messages sent to the UI) are internationalized using JBoss Logging. The log messages are accessed via the <code>org.jboss.as.quickstarts.kitchensink.util.KitchensinkMessages</code> interface, and the message bundles are located at: <code>src/main/resources/org/jboss/as/quickstarts/kitchensink/util/KitchensinkMessages.i18_(es|fr).properties</code></li>
<li>The message bundle consumed by Bean Validation is located at `src/main/resources/ValidationMessages.properties&#39; (this is defined by the bean validation specification).</li>
</ul></li>
<li><p>The following XML was added to the <code>src/main/webapp/WEB-INF/faces-config.xml</code> file. When you create a property file for a new language, you must add the supported locale to this file.</p>
<div class="highlight"><pre><span class="nt">&lt;application&gt;</span>
  <span class="nt">&lt;locale-config&gt;</span>
        <span class="nt">&lt;default-locale&gt;</span>en<span class="nt">&lt;/default-locale&gt;</span>
        <span class="nt">&lt;supported-locale&gt;</span>en-US<span class="nt">&lt;/supported-locale&gt;</span>
        <span class="nt">&lt;supported-locale&gt;</span>es<span class="nt">&lt;/supported-locale&gt;</span>
        <span class="nt">&lt;supported-locale&gt;</span>ES-FR<span class="nt">&lt;/supported-locale&gt;</span>
        <span class="nt">&lt;supported-locale&gt;</span>fr<span class="nt">&lt;/supported-locale&gt;</span>
        <span class="nt">&lt;supported-locale&gt;</span>fr-FR<span class="nt">&lt;/supported-locale&gt;</span>
    <span class="nt">&lt;/locale-config&gt;</span>
    <span class="nt">&lt;resource-bundle&gt;</span>
        <span class="nt">&lt;base-name&gt;</span>org/jboss/as/quickstarts/kitchensink/bundle/Resources<span class="nt">&lt;/base-name&gt;</span>
        <span class="nt">&lt;var&gt;</span>bundle<span class="nt">&lt;/var&gt;</span>
    <span class="nt">&lt;/resource-bundle&gt;</span>
<span class="nt">&lt;/application&gt;</span>
</pre></div></li>
<li><p>The <code>src/main/java/org/jboss/as/quickstarts/kitchensink/model/Member.java</code> file was modififed to add the message key to @Pattern annotation.</p>
<div class="highlight"><pre> <span class="err">@</span><span class="n">NotNull</span>
 <span class="err">@</span><span class="n">Size</span><span class="p">(</span><span class="n">min</span> <span class="o">=</span> <span class="mi">1</span><span class="p">,</span> <span class="n">max</span> <span class="o">=</span> <span class="mi">25</span><span class="p">)</span>
 <span class="err">@</span><span class="n">Pattern</span><span class="p">(</span><span class="n">regexp</span> <span class="o">=</span> <span class="s">&quot;[A-Za-z ]*&quot;</span><span class="p">,</span> <span class="n">message</span> <span class="o">=</span> <span class="s">&quot;{name_validation_message}&quot;</span><span class="p">)</span>
 <span class="n">private</span> <span class="n">String</span> <span class="n">name</span><span class="p">;</span>                
</pre></div></li>
<li><p>The <code>src/main/java/org/jboss/as/quickstarts/kitchensink/util/KitchensinkMessages.java</code> file was created, which defines default messages in English. The <code>jboss-logging-processor</code> will automatically generate an implementation for you, which can be accesssed via the <code>MESSAGES</code> static variable.</p>
<div class="highlight"><pre><span class="err">@</span><span class="n">MessageBundle</span><span class="p">(</span><span class="n">projectCode</span> <span class="o">=</span> <span class="s">&quot;&quot;</span><span class="p">)</span>
<span class="n">public</span> <span class="n">interface</span> <span class="n">KitchensinkMessages</span> <span class="p">{</span>

   <span class="n">KitchensinkMessages</span> <span class="n">MESSAGES</span> <span class="o">=</span> <span class="n">Messages</span><span class="p">.</span><span class="n">getBundle</span><span class="p">(</span><span class="n">KitchensinkMessages</span><span class="p">.</span><span class="n">class</span><span class="p">,</span> <span class="n">FacesContext</span><span class="p">.</span><span class="n">getCurrentInstance</span><span class="p">().</span><span class="n">getViewRoot</span><span class="p">().</span><span class="n">getLocale</span><span class="p">());</span>

   <span class="err">@</span><span class="n">Message</span><span class="p">(</span><span class="s">&quot;Registered!&quot;</span><span class="p">)</span>
   <span class="n">String</span> <span class="n">registeredMessage</span><span class="p">();</span>

   <span class="err">@</span><span class="n">Message</span><span class="p">(</span><span class="s">&quot;Successfully registered!&quot;</span><span class="p">)</span>
   <span class="n">String</span> <span class="n">registerSuccessfulMessage</span><span class="p">();</span>

   <span class="err">@</span><span class="n">Message</span><span class="p">(</span><span class="s">&quot;Registration failed:&quot;</span><span class="p">)</span>
   <span class="n">String</span> <span class="n">registerFailMessage</span><span class="p">();</span>

   <span class="err">@</span><span class="n">Message</span><span class="p">(</span><span class="s">&quot;Registration failed. See server log for more information.&quot;</span><span class="p">)</span>
   <span class="n">String</span> <span class="n">defaultErrorMessage</span><span class="p">();</span>
<span class="p">}</span>
</pre></div></li>
<li><p>The <code>src/main/java/org/jboss/as/quickstarts/kitchensink/controller/MemberController.java</code> file was modified as follows:</p>

<ul>
<li><p>Messages strings were replaced with strings retrieved using the resource bundle property names. For example:</p>
<div class="highlight"><pre><span class="n">FacesMessage</span> <span class="n">m</span> <span class="o">=</span> <span class="n">new</span> <span class="n">FacesMessage</span><span class="p">(</span><span class="n">FacesMessage</span><span class="p">.</span><span class="n">SEVERITY_INFO</span><span class="p">,</span> 
        <span class="n">KitchensinkMessages</span><span class="p">.</span><span class="n">MESSAGES</span><span class="p">.</span><span class="n">registeredMessage</span><span class="p">(),</span>
        <span class="n">KitchensinkMessages</span><span class="p">.</span><span class="n">MESSAGES</span><span class="p">.</span><span class="n">registerSuccessfulMessage</span><span class="p">());</span>
</pre></div></li>
</ul></li>
<li><p>The <code>src/main/webapp/index.xhtml</code> file were modified.</p>

<ul>
<li>Strings for headers, messages, labels were replaced with the appropriate <code># {bundle.&lt;property&gt;}</code>, for example: <code># {bundle.memberWelcomeHeader}</code>.</li>
</ul></li>
</ul>

<h3><a id="set-the-browser-preferred-locale" class="anchor" href="#set-the-browser-preferred-locale"><span class="anchor-icon"></span></a>Set the Browser Preferred Locale</h3>

<p>How you set your browser preferred locale depends on the browser and version you use. Use your browser help option to search for instructions to change the preferred language setting.</p>

<h2><a id="system-requirements" class="anchor" href="#system-requirements"><span class="anchor-icon"></span></a>System requirements</h2>

<p>The application this project produces is designed to be run on Red Hat JBoss Enterprise Application Platform 6.1 or later. </p>

<p>All you need to build this project is Java 6.0 (Java SDK 1.6) or later, Maven 3.0 or later.</p>

<p><em>Note: This quickstart uses the H2 database included with JBoss EAP 6. It is a lightweight, relational example datasource that is used for examples only. It is not robust or scalable and should NOT be used in a production environment!</em></p>

<h2><a id="configure-maven" class="anchor" href="#configure-maven"><span class="anchor-icon"></span></a>Configure Maven</h2>

<p>If you have not yet done so, you must <a href="../README.html#configure-maven">Configure Maven</a> before testing the quickstarts.</p>

<h2><a id="start-the-jboss-server" class="anchor" href="#start-the-jboss-server"><span class="anchor-icon"></span></a>Start the JBoss Server</h2>

<ol>
<li>Open a command line and navigate to the root of the JBoss server directory.</li>
<li><p>The following shows the command line to start the server:</p>
<div class="highlight"><pre><span class="n">For</span> <span class="n">Linux</span><span class="o">:</span>   <span class="n">JBOSS_HOME</span><span class="o">/</span><span class="n">bin</span><span class="o">/</span><span class="n">standalone</span><span class="p">.</span><span class="n">sh</span>
<span class="n">For</span> <span class="n">Windows</span><span class="o">:</span> <span class="n">JBOSS_HOME</span><span class="err">\</span><span class="n">bin</span><span class="err">\</span><span class="n">standalone</span><span class="p">.</span><span class="n">bat</span>
</pre></div></li>
</ol>

<h2><a id="build-and-deploy-the-quickstart" class="anchor" href="#build-and-deploy-the-quickstart"><span class="anchor-icon"></span></a>Build and Deploy the Quickstart</h2>

<p><em>NOTE: The following build command assumes you have configured your Maven user settings. If you have not, you must include Maven setting arguments on the command line. See <a href="../README.html#build-and-deploy-the-quickstarts">Build and Deploy the Quickstarts</a> for complete instructions and additional options.</em></p>

<ol>
<li>Make sure you have started the JBoss Server as described above.</li>
<li>Open a command line and navigate to the root directory of this quickstart.</li>
<li><p>Type this command to build and deploy the archive:</p>
<div class="highlight"><pre><span class="n">mvn</span> <span class="n">clean</span> <span class="n">install</span> <span class="n">jboss</span><span class="o">-</span><span class="n">as</span><span class="o">:</span><span class="n">deploy</span>
</pre></div></li>
<li><p>This will deploy <code>target/jboss-kitchensink-ml.war</code> to the running instance of the server.</p></li>
</ol>

<h2><a id="access-the-application-" class="anchor" href="#access-the-application-"><span class="anchor-icon"></span></a>Access the application </h2>

<p>The application will be running at the following URL: <a href="http://localhost:8080/jboss-kitchensink-ml/">http://localhost:8080/jboss-kitchensink-ml/</a>.</p>

<p>Change your browser preferred language to French or Spanish and refresh the page to see it displayed in the new language. </p>

<h2><a id="undeploy-the-archive" class="anchor" href="#undeploy-the-archive"><span class="anchor-icon"></span></a>Undeploy the Archive</h2>

<ol>
<li>Make sure you have started the JBoss Server as described above.</li>
<li>Open a command line and navigate to the root directory of this quickstart.</li>
<li><p>When you are finished testing, type this command to undeploy the archive:</p>
<div class="highlight"><pre><span class="n">mvn</span> <span class="n">jboss</span><span class="o">-</span><span class="n">as</span><span class="o">:</span><span class="n">undeploy</span>
</pre></div></li>
</ol>

<h2><a id="run-the-arquillian-tests-" class="anchor" href="#run-the-arquillian-tests-"><span class="anchor-icon"></span></a>Run the Arquillian Tests </h2>

<p>This quickstart provides Arquillian tests. By default, these tests are configured to be skipped as Arquillian tests require the use of a container. </p>

<p><em>NOTE: The following commands assume you have configured your Maven user settings. If you have not, you must include Maven setting arguments on the command line. See <a href="../README.html#run-the-arquillian-tests">Run the Arquillian Tests</a> for complete instructions and additional options.</em></p>

<ol>
<li>Make sure you have started the JBoss Server as described above.</li>
<li>Open a command line and navigate to the root directory of this quickstart.</li>
<li><p>Type the following command to run the test goal with the following profile activated:</p>
<div class="highlight"><pre><span class="n">mvn</span> <span class="n">clean</span> <span class="n">test</span> <span class="o">-</span><span class="n">Parq</span><span class="o">-</span><span class="n">jbossas</span><span class="o">-</span><span class="n">remote</span> 
</pre></div></li>
</ol>

<h2><a id="run-the-quickstart-in-jboss-developer-studio-or-eclipse" class="anchor" href="#run-the-quickstart-in-jboss-developer-studio-or-eclipse"><span class="anchor-icon"></span></a>Run the Quickstart in JBoss Developer Studio or Eclipse</h2>

<p>You can also start the server and deploy the quickstarts from Eclipse using JBoss tools. For more information, see <a href="../README.html#use-jboss-developer-studio-or-eclipse-to-run-the-quickstarts">Use JBoss Developer Studio or Eclipse to Run the Quickstarts</a> </p>

<h2><a id="debug-the-application" class="anchor" href="#debug-the-application"><span class="anchor-icon"></span></a>Debug the Application</h2>

<p>If you want to debug the source code or look at the Javadocs of any library in the project, run either of the following commands to pull them into your local repository. The IDE should then detect them.</p>
<div class="highlight"><pre><span class="n">mvn</span> <span class="n">dependency</span><span class="o">:</span><span class="n">sources</span>
<span class="n">mvn</span> <span class="n">dependency</span><span class="o">:</span><span class="n">resolve</span> <span class="o">-</span><span class="n">Dclassifier</span><span class="o">=</span><span class="n">javadoc</span>
</pre></div></body></html>
